#include "LinkQueue.cpp"

// 输出约瑟夫序列
void JSequence(int n, int m)
{
    int x;
    LinkQueue<int> qu;  // 定义一个链队
    // 编号为1到n的小孩进队
    for(int i = 1; i <= n; i++)
        qu.push(i);

    for(int i = 1; i <= n; i++) // 共出列n个小孩
    {
        int j = 1;
        while(j <= m-1) // 出队m-1个小孩，并将他们进队
        {
            qu.pop(x);
            qu.push(x);
            j++;
        }
        qu.pop(x);      // 出队第m个小孩
        cout << x << " ";
    }
    cout << endl;
}
int main() {
    cout << "Test1: n=6, m=3" << std::endl;
    cout <<"dequeue sequence:";
    JSequence(6, 3);
    cout << "Test1: n=8, m=4" << std::endl;
    cout <<"dequeue sequence:";
    JSequence(8, 4);
    return 0;
}
